#############################
# caculating Japan's ENPP  #
#############################

###library

library(tidyverse)


### japan enpp

japan_seat<-read.csv("japan_seatshare.csv")
attach(japan_seat)
japan_seat$perseat=absseat/totseats
japan_seat<-na.omit(japan_seat)



##calculate two types of ENPP

#molinar

tb_enpp_np<-
  japan_seat %>%group_by(edate) %>%
  summarise(enpp_np=1+(1/(sum(perseat^2))*((sum(perseat^2)-max(perseat^2))/sum(perseat^2))))

#laakso
tb_enpp<-japan_seat %>%group_by(edate) %>%
  summarise(enpp=1/sum(perseat^2))

#combine two tibbles
enpp_japan<-data.frame(tb_enpp_np,tb_enpp)

#output.csv
write.csv(enpp_japan,"enpp_japan.csv")